﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

using OrandoLabs.Inquiro;
using OrandoLabs.OpenSource.Inquiro;

namespace InquiroBulkLoaderCommand
{
    class AnInquiroBulkFolderLoader : InquiroBulkFolderLoader
    {
        public AnInquiroBulkFolderLoader(String name, String dir, String textsDir)
            : base(name, dir, textsDir, true)
        {
        }

        public override void LoadComplete()
        {
            Term[] termsEven = new Term[] {
                    new SearchTextTerm("preserve"),
                    new SearchTextTerm("the"),
                    new SearchTextTerm("sense")
                };

            Term[] termsOdd = new Term[] {
                    new SearchTextTerm("dogmatic"),
                    new SearchTextTerm("decisions"),
                    new SearchTextTerm("compromised")
                };

            int Loop = 10000;
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
            for (int i = 0; i < Loop; i++)
            {
                int even = i % 2;
                List<Tuple<PhraseIndex, PhraseIndex>> phrases;
                if (even == 0)
                    phrases = Ctx.FindPhrases(termsEven, 0, 5);
                else
                    phrases = Ctx.FindPhrases(termsOdd, 0, 5);
                int count = phrases.Count;
            }
            timer.Stop();
            var seconds = timer.ElapsedMilliseconds / 1000;
            var qps = (float)Loop / (float)seconds;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            String instance = args[0];
            String dir = args[1];
            String textsDir = Path.Combine(dir, "texts");
            String instanceDir = Path.Combine(dir, instance);

            AnInquiroBulkFolderLoader loader = new AnInquiroBulkFolderLoader(instance, instanceDir, textsDir);
            Task<bool> loaded = loader.Load((Target target) =>
                {
                    Console.WriteLine("Loaded target " + target.target);
                    return true;
                }
            );
            loaded.Wait();
        }
    }
}
